/*    */ package org.jeecgframework.p3.cg;
/*    */ 
/*    */ import java.io.BufferedWriter;
/*    */ import java.io.File;
/*    */ import java.io.FileOutputStream;
/*    */ import java.io.OutputStreamWriter;
/*    */ import java.util.Properties;
/*    */ import org.apache.commons.logging.Log;
/*    */ import org.apache.commons.logging.LogFactory;
/*    */ import org.apache.velocity.Template;
/*    */ import org.apache.velocity.VelocityContext;
/*    */ import org.apache.velocity.app.VelocityEngine;
/*    */ import org.jeecgframework.p3.cg.def.CodeResourceUtil;
/*    */ import org.jeecgframework.p3.cg.factory.CodeGenerateFactory;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CommonPageParser
/*    */ {
/*    */   private static VelocityEngine ve;
/*    */   private static final String CONTENT_ENCODING = "UTF-8";
/* 34 */   private static final Log log = LogFactory.getLog(CommonPageParser.class);
/*    */   
/* 36 */   private static boolean isReplace = true;
/*    */   
/*    */ 
/*    */   static
/*    */   {
/*    */     try
/*    */     {
/* 43 */       String templateBasePath = CodeGenerateFactory.getProjectPath() + CodeResourceUtil.getConfigInfo("templatepath_vm");
/* 44 */       Properties properties = new Properties();
/* 45 */       properties.setProperty("resource.loader", "file");
/* 46 */       properties.setProperty("file.resource.loader.description", "Velocity File Resource Loader");
/* 47 */       properties.setProperty("file.resource.loader.path", templateBasePath);
/* 48 */       properties.setProperty("file.resource.loader.cache", "true");
/* 49 */       properties.setProperty("file.resource.loader.modificationCheckInterval", "30");
/* 50 */       properties.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute");
/* 51 */       properties.setProperty("runtime.log.logsystem.log4j.logger", "org.apache.velocity");
/* 52 */       properties.setProperty("directive.set.null.allowed", "true");
/* 53 */       VelocityEngine velocityEngine = new VelocityEngine();
/* 54 */       velocityEngine.init(properties);
/* 55 */       ve = velocityEngine;
/*    */     } catch (Exception e) {
/* 57 */       log.error(e);
/*    */     }
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   public static void WriterPage(VelocityContext context, String templateName, String fileDirPath, String targetFile)
/*    */   {
/*    */     try
/*    */     {
/* 72 */       String workspasePath = CodeResourceUtil.getConfigInfo("workspace_path");
/* 73 */       File file = new File(workspasePath + File.separator + fileDirPath + File.separator + targetFile);
/* 74 */       if (!file.exists()) {
/* 75 */         new File(file.getParent()).mkdirs();
/*    */       }
/* 77 */       else if (isReplace) {
/* 78 */         log.info("替换文件:" + file.getAbsolutePath());
/*    */       }
/*    */       
/*    */ 
/*    */ 
/* 83 */       Template template = ve.getTemplate(templateName, "UTF-8");
/* 84 */       FileOutputStream fos = new FileOutputStream(file);
/* 85 */       BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
/* 86 */       template.merge(context, writer);
/* 87 */       writer.flush();
/* 88 */       writer.close();
/* 89 */       fos.close();
/* 90 */       log.info("生成文件：" + file.getAbsolutePath());
/*    */     } catch (Exception e) {
/* 92 */       log.error(e);
/*    */     }
/*    */   }
/*    */ }


/* Location:              /Users/guo/.m2/repository/org/jeewxframework/P3-Codegenerate/2.0.1/P3-Codegenerate-2.0.1.jar!/org/jeecgframework/p3/cg/CommonPageParser.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */